import http from './http'
export const LoginApi = (params: ILoginParams): RSP<ILoginResponse> => http.post('/admin/login', params);

// 用于向服务器请求当前用户的权限列表的函数。
export const GetCurrentUserInfoApi = (): RSP<IUserInfoModel> => http.get('/admin/info');

// 分页查询用户列表的api函数
export const queryUserListByPageApi = (params: IQueryUserListParams, config?: any): RSP<IUserListResponse<IUserListModel>> => http.get('/admin/list', { params, cancelToken: config.cancelToken })

// 启用禁用用户的请求 -- 注意：有时候后端会要求我们在 请求地址上传递参数
export const enableUserApi = (params: IEnableUserStatusParams): RSP<number> => http.post(`/admin/updateStatus/${params.id}?status=${params.status}`)

// 添加用户的函数
export const addUserInfoApi = (params: IUserModel): RSP<IUserListModel> => http.post('/admin/register', params)

export const queryEditUserApi = (id: number): RSP<IUserListModel> => http.get(`/admin/${id}`)

export const updadateUserInfoApi = (params: IUserListModel): RSP<number> => http.post(`/admin/update/${params.id}`, params)

export const getAllRoleListApi = (): RSP<IRoleModel[]> => http.get('/role/listAll');

export const getRoleListByUserIdAPi = (adminId: number): RSP<IRoleModel[]> => http.get(`/admin/role/${adminId}`)

export const updateUserRoleApi = (params: IUpdateUserRoleParmas): RSP<number> => http.post(`/admin/role/update?adminId=${params.adminId}&roleIds=${params.roleIds.join(',')}`)


export const getRoleListApi = (params: IQueryUserListParams): RSP<IUserListResponse<IRoleModel>> => http.get('/role/list', { params })

// 请求所有的菜单数据
export const getAllMenuApi = (): RSP<IMenuModelWidthChildren[]> => http.get(`/menu/treeList`)
// 根据id请求对应的角色拥有的菜单
export const getMenusByRoleIdApi = (roleId: number): RSP<IMenuModel[]> => http.get(`/role/listMenu/${roleId}`)

export const allocRomeMenuApi = (params: IAlocRoleMenuParams) => http.post(`/role/allocMenu?roleId=${params.roleId}&menuIds=${params.menuIds.join(',')}`)

export const getAllResourceApi = (): RSP<IResourceModel[]> => http.get(`/resource/listAll`)

export const getRoleResourceApi = (roleId: number): RSP<IResourceModel[]> => http.get(`/role/listResource/${roleId}`)

export const getAllResourceTypeApi = (): RSP<IResourceCategoryModel[]> => http.get(`/resourceCategory/listAll`)

export const getHomeDataApi = (): RSP<IHomeData> => http.get(`http://kumanxuan1.f3322.net:8360/admin/stat`)